var Modifypassword = new Vue({
	
	el : '#Adminlist',
	data :{

		user:{},
		
		adminlist:[],
		
		userId : $("#id").val(),
		loginname: '',
        loginpassword: '',
        againloginpassword:'',
        isvalid:'1',
        
		editFlag : 1,					// 0:新增，1：修改
		
	},
	created : function() {

		$(".nav navbar-nav li").removeClass("active");
		$("#nav_modifypassword").addClass("active");
		this.bindUser();
		
	},
	
	methods : {

		bindUser :function(){
			
			var _this = this;
			layer.open({type:3});
			$.post('/user/find_one', {
				userID : _this.userId,
				rdm : Math.random()
			},function(ppData) {
				layer.closeAll("loading");
				if(ppData != null){
					
					if(ppData.result == "1"){
						var data = ppData.resultContent
						_this.user = data;
					}else{
						layer.alert(ppData.message);
					}
				}
			},"json");						
		},

		modifypsw : function(){
			
			var _this = this;
			
			if(_this.checkInputData()){		
				$.post('/user/modifypsw',{

					userID : _this.userId,
					//loginname:$.trim(_this.admin.loginname),
					password:$.trim(_this.user.againpassword),
					random : Math.random()
				},function(ppData){
					if(ppData != null){
						layer.closeAll("loading");
						
						if(ppData.result == "1"){
							layer.open({
								time:1000,
								btn:[],
								content:"修改成功!",
							});
							location.href = "../../vote/xiangmu";
							//_this.bindAdmin();
					   }else{
						   layer.alert(ppData.message);
					   }
					}
				},"json");
			}
		},
		
	

		//检查输入信息
		checkInputData : function(){
			var _this=this;
			
			// var loginname = !_this.admin.loginname ? "" : $.trim(_this.admin.loginname);
			// if("" == loginname){
			// 	layer.alert("请填写登录账户！");
			// 	this.$refs.loginname.focus();
	    	// 	return false;
			// }
			//
			var loginpassword = $.trim(_this.user.password);
			if(!loginpassword){
				layer.alert("请填写登录密码！");
	    		return false;
			}
			
			var againloginpassword = $.trim(_this.user.againpassword);
			if(!againloginpassword){
				layer.alert("请填写重复密码！");
	    		return false;
			}
			
			if(loginpassword != againloginpassword){
				layer.alert("两次密码不一致！");
				return false;
			}
			
			return true;
		},
		
	},
	
	watch :{
		//监控分页情况，刷新列表
		pageIndex : function(){
			this.bindAdmin();
		}
	}
	
});
